/*****************************************************************
 MYD Engine v0.1

 File: myd_importer.cpp
 Created: 02/07/09
*****************************************************************/
#include "myd_importer.h"
#include "graphics/myd_renderer.h"

using namespace myd;

//----------------------------------------------------------------constructor
Importer::Importer(Renderer *tm_Renderer)
:
wn_Renderer(tm_Renderer)
{}

//----------------------------------------------------------------destructor
Importer::~Importer(void)
{
	/*/ delete all the prototype sprites
	for( std::map<std::string, Sprite*>::iterator it = spritesMap.begin(), e = spritesMap.end(); it != e; )
	{
	}*/
}

/*/----------------------------------------------------------------getTexture
Texture::Ptr Importer::getTexture (const char* fileName)
{
	Texture::Ptr tm_Texture = texturesMap[fileName];
	Texture::Ptr pkNewTexture(new Texture(*tm_Texture));
	return pkNewTexture;
}*/

//----------------------------------------------------------------------
bool Importer::importXFile(char* filename, Entity3d &tm_mesh, LPDIRECT3DDEVICE9 tm_device)
{
/*	DWORD materialsAmm;
	LPD3DXBUFFER materialsBuffer;
	//LPD3DXBUFFER adjacencyBuffer;
	std::vector<D3DMATERIAL9> materialsVector;
	std::vector<IDirect3DTexture9*> texturesVector;

	HRESULT hr;
	hr = D3DXLoadMeshFromX(filename,
						   D3DXMESH_SYSTEMMEM,
						   tm_device,
						   NULL,
						   &materialsBuffer,
						   NULL,
						   &materialsAmm,
						   &tm_mesh.wn_mesh);

	if(FAILED(hr))
	{
		::MessageBox(0, "Error al cargar el archivo :)", "Error",0); return false;
	}

	
	D3DMATERIAL9 *material;
	D3DXMATERIAL *tempMaterials = (D3DXMATERIAL*)materialsBuffer->GetBufferPointer();

	material = new D3DMATERIAL9[materialsAmm];

	for(DWORD i = 0; i < materialsAmm; i++)
	{
		material[i] = tempMaterials[i].MatD3D;
		material[i].Ambient = material[i].Diffuse;

		materialsVector.push_back(tempMaterials[i].MatD3D);

		if(tempMaterials[i].pTextureFilename != NULL)
		{
			IDirect3DTexture9 *texture = 0;
			D3DXCreateTextureFromFile(tm_device, tempMaterials[i].pTextureFilename, &texture);
			texturesVector.push_back(texture);
		}else{
			texturesVector.push_back(0);
		}
	}

	//tm_mesh.wn_mesh->OptimizeInplace(D3DXMESHOPT_ATTRSORT, (DWORD*)adjacencyBuffer->GetBufferPointer(),0,0,0);

	tm_device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	tm_device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
*/	
	return true;
}